import threading, time, queue
from imports import *
import reptil_thread
class reptil_a_place():               # 爬取单个景区页面信息
    def __init__(self, url):
        self.Headers = Headers
        self.url = url
        if len(url) > 0:
            self.q = rq.get(url=url, headers = self.Headers)  # 获取html
            self.soup = bs(self.q.text, 'html.parser')  # soup解析html
    def getAll(self):          # 获取景区信息

        text = [str(x) for x in self.soup.select('.moduleContent')]  # 通过类名获取 景区信息
        INSTRUCTION = re.findall('>([^<]+)<', text[0].replace("<span>", "").replace("</span>",""))[0]           # 景区介绍信息
        OPENTIME = re.findall('>([\\-0-9:^<]+)<', text[1])[0]                                                   # 景区开放时间信息
        WAY = re.findall('>([^<]+)<', text[2])[0]                                                               # 步行方式信息
        TEL = re.findall('<p class="baseInfoText">([\\-0-9^<]+)</p>', ''.join([str(x) for x in self.soup.select('.baseInfoText')]))[0] # 联系电话信息

        COMMENT = [str(x) for x in self.soup.select('.hotTag')]                                                      # 评论 总结 所在标签
        COMMENT = re.findall('>([^<]+)<!-- -->[(]([0-9]+)[)]</span>', ''.join(COMMENT))                         # 评论总结 信息
        return [INSTRUCTION, OPENTIME, WAY, TEL, COMMENT]                                                       # 返回景区信息

    def getAImageLink(self, name):  # 随机返回 一个图片链接
        n = len(self.imagesLink[name])
        i = random.randint(0, n - 1)
        return self.imagesLink[name][i]

    def initImageLink(self):
        reptil_thread.work()
        self.imagesLink = reptil_thread.imagesLink
